"""
    在admin中注册模型
"""

import hashlib
from django.contrib import admin
from .models import App

# Register your models here.

# admin.site.register(App) # 简单注册

@admin.register(App)
class ApisAppAdmin(admin.ModelAdmin):
    fields = ['name', 'application', 'category', 'url', 'publish_date', 'desc'] # 表示这些字段在 admin 中展示

    pass

    # 重写 父类admin.ModelAdmin 的保存方法
    def save_model(self, request, obj, form, change):
        src = obj.category + obj.application
        appid = hashlib.md5(src.encode('utf8')).hexdigest()
        obj.appid = appid
        super().save_model(request, obj, form, change)
